#pragma region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#pragma endregion

#pragma once

class OSHMixerPlugin;

/// <summary>
/// VMRStateController class monitor filter graph notifications and control VMR state.
/// OSH Mixer Plugin should inform this class  about all its filter graph changes.
/// This class helps to avoid setting multiple VMR instances (from different graphs)
/// in Mixing Mode, which can lead to failures during VMR connection to an upstream filter.
/// </summary>
class VMRStateController
{
private:
	ATL::CMutex _mixingModeMutex;
	Utils::CMutexLock _mixingModeMutexLock;

	IUnknown* _vmrFilterGraph;
	IUnknown* _vmrInMixingMode;

	HRESULT HasFilterGraphChanged(IFilterGraph* filterGraph);
	HRESULT SaveVMRState(IFilterGraph* filterGraph, IBaseFilter* vmrFilter);
	void ClearVMRState();
	bool IsVMRStateSaved();

public:
	VMRStateController();
	~VMRStateController();

	HRESULT NotifyGraphChange(IFilterGraph* filterGraph);
	HRESULT NotifyMixingModeSet(IFilterGraph* filterGraph, IBaseFilter* vmrFilter);

	HRESULT CanSetMixingMode();
};

